package com.ptkc.web;

import com.ptkc.constants.WebResult;
import org.apache.lucene.search.join.ScoreMode;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.index.query.NestedQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author: Mr.Jiao
 * @date: 2018年12月06日
 */
@RestController
@RequestMapping(value = {"/activity", "search/activity"})
public class ActivitiesController {


    private final String INDEX = "runfast_business";

    @Autowired
    private RestHighLevelClient restHighLevelClient;

    @GetMapping(value = "/list")
    public WebResult<Object> getActivities(@PageableDefault Pageable pageable, HttpServletRequest request) throws IOException {
        SearchRequest searchRequest = new SearchRequest();
        SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
        NestedQueryBuilder nestedQueryBuilder = new NestedQueryBuilder("activities", QueryBuilders.boolQuery(), ScoreMode.None);
        sourceBuilder.query(nestedQueryBuilder);
        searchRequest.source(sourceBuilder).indices(INDEX);
        System.out.println(searchRequest.source());
        SearchResponse response = restHighLevelClient.search(searchRequest);
        return null;
    }


}
